/**时间日期显示组件 */
import { Text } from "@tarojs/components";
import { isNumber } from "@tarojs/shared";
import dayjs, { Dayjs } from "dayjs";

const formatMap = {
  month: "MM-DD",
  year: "YYYY-MM-DD",
  full: "YYYY-MM-DD HH:mm:ss",
};

type Moment = {
  value?: number | string | Dayjs;
  type?: keyof typeof formatMap;
  className?: string;
  placeholder?: string;
};

export default ({ className, value, type = "year", placeholder }: Moment) => {
  const formatType = formatMap[type];
  const val = (value ? isNumber(value) ? dayjs.unix(value) : dayjs(value) : undefined)?.format(formatType)
  return <Text className={className}>{val || placeholder}</Text>;
};
